package edu.cuit.svsp.service.impl;

import edu.cuit.svsp.entity.Category;
import edu.cuit.svsp.mapper.CategoryMapper;
import edu.cuit.svsp.service.CategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @className: CategoryServiceImpl
 * @author: pjy
 * @description: 分类服务实现类
 * @date: 2024/7/3
 */
@Service
public class CategoryServiceImpl implements CategoryService {
    @Resource
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> findAll() {
        List<Category> categories = categoryMapper.findAll();
        return categories;
    }

    @Override
    public List<Category> list() {
        return categoryMapper.list();
    }

    @Override
    public boolean lock(Integer id) {
        return categoryMapper.lock(id);
    }

    @Override
    public boolean pass(Integer id) {
        return categoryMapper.pass(id);
    }

    @Override
    public boolean edit(Category category) {
        Integer flag=categoryMapper.findName(category.getName());
        if(flag==0){
            if(category.getId() == 0){
                return categoryMapper.add(category);
            }else{
                return categoryMapper.update(category);
            }
        }else {
            return false;
        }
    }

    @Override
    public List<Category> search(String name) {
        return categoryMapper.search(name);
    }
}
